<template>
  <form 
    class="advanced-form" 
    :class="`advanced-form--${layout}`"
    @submit.prevent="handleSubmit"
  >
    <slot></slot>
  </form>
</template>

<script setup>
import { provide, ref } from 'vue'

defineProps({
  layout: {
    type: String,
    default: 'horizontal', // horizontal, vertical, inline
    validator: (value) => ['horizontal', 'vertical', 'inline'].includes(value)
  },
  labelPosition: {
    type: String,
    default: 'left', // left, right, top
    validator: (value) => ['left', 'right', 'top'].includes(value)
  },
  labelWidth: {
    type: String,
    default: '100px'
  },
  showMessage: {
    type: Boolean,
    default: true
  }
})

const emit = defineEmits(['submit', 'validate'])

// 提供表单相关属性给子组件
provide('formContext', {
  labelPosition: ref('left'),
  labelWidth: ref('100px'),
  showMessage: ref(true)
})

const handleSubmit = (event) => {
  emit('submit', event)
}
</script>

<style scoped>
.advanced-form {
  background: var(--color-white);
  padding: var(--spacing-large);
  border-radius: var(--border-radius-large);
  box-shadow: var(--box-shadow-base);
}

.advanced-form--vertical .advanced-form-item {
  flex-direction: column;
}

.advanced-form--vertical .advanced-form-item__label {
  margin-bottom: var(--spacing-small);
  text-align: left;
}

.advanced-form--inline {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-medium);
  align-items: flex-start;
}

.advanced-form--inline .advanced-form-item {
  flex: 1;
  min-width: 200px;
  margin-bottom: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .advanced-form {
    padding: var(--spacing-medium);
  }
  
  .advanced-form--inline {
    flex-direction: column;
  }
  
  .advanced-form--inline .advanced-form-item {
    min-width: 100%;
  }
}
</style>